package com.mtl.inmigrant.shoes.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.mtl.inmigrant.shoes.R;
import com.mtl.inmigrant.shoes.entity.ShoeActionsInmigrant;
import com.mtl.inmigrant.shoes.sqlite.ShoesDataSource;

public class ReferentialListAdapter extends BaseAdapter {
	//protected final Activity context;
	private LayoutInflater inflator;
	private OnCustomClickListener callback;
	private List<ShoeActionsInmigrant> list;
	private ShoesDataSource dataSource;
	private String idActivityParent;
	private String idTask;
	private Context context;
	private RadioGroup radioGroup;

	public ReferentialListAdapter(Context context, List<ShoeActionsInmigrant> list, ShoesDataSource dataSource, OnCustomClickListener callback, String idActivity, String idTask, RadioGroup radioGroup) {
		inflator = LayoutInflater.from(context);
		this.list = list;
		this.callback = callback;
		this.dataSource = dataSource;
		this.idActivityParent = idActivity;
		this.idTask = idTask;
		this.context = context;
		this.radioGroup = radioGroup;
	}

	static class ViewHolder {
		protected String idElement;
		protected RadioButton radioButtion;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		ShoeActionsInmigrant shoeActionInmigrant = (ShoeActionsInmigrant) this.getItem(position);
		if (convertView == null) {

			convertView = inflator.inflate(R.layout.row_radiobutton, parent, false);
			viewHolder = new ViewHolder();
			viewHolder.radioButtion = new RadioButton(context);
			viewHolder.radioButtion.setText(shoeActionInmigrant.getNameAction()); 
			viewHolder.radioButtion.setId(position); 
            radioGroup.addView(viewHolder.radioButtion);
            radioGroup.setTag(shoeActionInmigrant);
			convertView.setTag(viewHolder);
			

			/*
			viewHolder.checkbox
					.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
						public void onCheckedChanged(CompoundButton buttonView,
								boolean isChecked) {
							CheckBox cb = (CheckBox) buttonView;
							ShoeActionsInmigrant element = (ShoeActionsInmigrant) cb.getTag();
							element.setStatus(cb.isChecked());
							dataSource.updateActivity(new String[]{element.getIdActivity(), idActivityParent}, (isChecked==true) ? new Integer(1) : new Integer(0), typeActionShoe.TASK.toString());

						}
					});
					*/
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		convertView.setOnClickListener(new CustomOnClickListener(callback, position));
		return convertView;
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int arg0) {
		return list.get(arg0);
	}

	public long getItemId(int arg0) {
		return 0;
	}

}